package com.jet.merchant.controller;

import com.jet.merchant.domain.dto.ResourceDto;
import com.jet.merchant.domain.query.ResourcePageQuery;
import com.jet.merchant.domain.vo.ResourceVo;
import com.jet.merchant.service.IClerkResourceService;
import com.jet.core.model.vo.PageVo;
import com.jet.core.result.ResultJson;
import org.springframework.web.bind.annotation.*;

/**
 * 资源管理
 */
@RestController
@RequestMapping("/clerk/resource")
public class ResourceController {

    private final IClerkResourceService clerkResourceService;

    public ResourceController(IClerkResourceService clerkResourceService) {
        this.clerkResourceService = clerkResourceService;
    }

    @PostMapping
    public ResultJson<Void> create(@RequestBody ResourceDto dto) {
        clerkResourceService.save(dto);
        return ResultJson.ok();
    }

    @PutMapping("/{id}")
    public ResultJson<Void> edit(@PathVariable("id") String id,
                                 @RequestBody ResourceDto dto) {
        clerkResourceService.edit(id, dto);
        return ResultJson.ok();
    }

    @DeleteMapping("/{id}")
    public ResultJson<Void> delete(@PathVariable("id") String id) {
        clerkResourceService.removeById(id);
        return ResultJson.ok();
    }

    @GetMapping("/{id}")
    public ResultJson<ResourceVo> info(@PathVariable("id") String id) {
        ResourceVo vo = clerkResourceService.info(id);
        return ResultJson.ok(vo);
    }

    @GetMapping("/page")
    public ResultJson<PageVo<ResourceVo>> page(ResourcePageQuery query) {
        PageVo<ResourceVo> vo = clerkResourceService.page(query);
        return ResultJson.ok(vo);
    }
}
